use Archive::Extract;
use IO::All;


#use Data::Printer;

sub extract {
    
    my ($file, $extract_path) = @_;
    #print "extract_path -> $extract_path \n";
    
    if ($file && $extract_path){
    	
    	my $ae = Archive::Extract->new( archive => $file );
        #$ae->extract_path($extract_path);

        my $ok = $ae->extract( to => $extract_path ) or die $ae->error;
    	
    	print "Extract $file \n\t to  \[ $extract_path \] ...... ok.\n" if $ok;
    }
	
}


sub extract_data {
	my $hash = shift;
	
	my $file_path = $hash->{from} or die "file path undefined!";
	my $extract_path = $hash->{to} or die "extract path undefined!";
	#print "Extra to: $extract_path\n";
	#my @files = io->dir($file_path)->all or die "there is no file to extract!";
	#p @files;
	
	
	#tie %dir, 'IO::Dir', $file_path;
	my $io = io($file_path);
	my @files = $io->all_files(1);
	for (@files)
	{
		my $file =  $_->name;
		extract($file, $extract_path);
	} 
	my $count = @files;
	print "\nTotal extract: $count files .\n";

	
	
}



my $hr = { from => 'd:\cudatext\CudaText_addons\lexer',
             to   => 'd:\cudatext\data\lexlib'};

extract_data($hr);


my $aoh = [
              {from => 'D:\cudatext\CudaText_addons\translation', to => 'D:\cudatext\data\lang'}, 
              {from => 'D:\cudatext\CudaText_addons\lexer', to => 'D:\cudatext\data\lexlib'},
              {from => 'D:\cudatext\CudaText_addons\theme', to => 'D:\cudatext\data\themes'},
              {from => 'D:\cudatext\CudaText_addons\snippets_ct', to => 'D:\cudatext\data\snippets_ct'},


];


for (@$aoh) {
	extract_data($_);
}
__END__
#my $fn = 'D:\cudatext\CudaText_addons\lexer\lexer.FoxPro.zip';
#my $extr_path = 'D:\cudatext\data\lexlib';

#extract($fn, $extr_path);